home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Demo ƒ / WEDemoIntf.c < prev    next >
Text File  |  1996-05-19  |  2KB  |  108 lines

  1. /*
  2.     WASTE Demo Project:
  3.     Utility Functions
  4.  
  5.     Copyright © 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     In Pascal, an "intf" file is sorta like a .h (header) file in C:  it contains a lot
  13.     of the declarations and definitions of things used in general by the entirity of
  14.     the code.
  15.  
  16.     Most of the code from the WEDemoIntf.p file has been placed into the WEDemoHeader.h
  17.     file except for some general purpose utility functions, which have then been
  18.     placed here.
  19. */
  20.  
  21. #ifndef    __WEDEMOAPP__
  22. #include "WEDemoIntf.h"
  23. #endif
  24.  
  25. Boolean        gHasColorQD = false;
  26. Boolean        gHasDragAndDrop = false;
  27. Boolean        gHasTextServices = false;
  28. Boolean        gExiting = false;
  29.  
  30.  
  31. DocumentHandle GetWindowDocument( WindowRef window )
  32. {
  33.     // make sure window is not nil and is one of our windows
  34.     if (( window == nil ) || ( GetWindowKind( window ) != userKind ))
  35.         return nil;
  36.  
  37.     // a handle to the document structure is kept in the window refCon
  38.     return (DocumentHandle) GetWRefCon( window );
  39. }
  40.  
  41. void ErrorAlert( OSErr err )
  42. {
  43.     Str255 errString;
  44.  
  45.     NumToString( err, errString );
  46.     ParamText( errString, nil, nil, nil );
  47.  
  48.     SetCursor( &qd.arrow );
  49.  
  50.     Alert( kAlertGenError, GetMyStandardDialogFilter( ) );
  51. }
  52.  
  53. void ForgetHandle( Handle *h )
  54. {
  55.     Handle theHandle;
  56.  
  57.     if ( ( theHandle = *h ) != nil )
  58.     {
  59.         *h = nil;
  60.         DisposeHandle( theHandle );
  61.     }
  62. }
  63.  
  64. void ForgetResource( Handle *h )
  65. {
  66.     Handle theHandle;
  67.  
  68.     if ( ( theHandle = *h ) != nil )
  69.     {
  70.         *h = nil;
  71.         ReleaseResource( theHandle );
  72.     }
  73. }
  74.  
  75. OSErr NewHandleTemp( Size blockSize, Handle *h )
  76. {
  77.     OSErr err;
  78.  
  79.     // allocate a new relocatable block from temporary memory, or
  80.     // if that fails, from the current heap
  81.  
  82.     // first try tapping temporary memory
  83.  
  84.     *h = TempNewHandle( blockSize, &err );
  85.  
  86.     // in case of failure, try with current heap
  87.  
  88.     if ( *h == nil )
  89.     {
  90.         *h = NewHandle( blockSize );
  91.         err = MemError( );
  92.     }
  93.  
  94.     return err;
  95. }
  96.  
  97. // this is a function not originally in the WASTE Demo App, however due to the
  98. // differences between Pascal and C, it's necessary to have to accomplish things.
  99.  
  100. void PStringCopy( ConstStr255Param srcString, Str255 destString )
  101. {
  102.     register short index = StrLength( srcString );
  103.  
  104.     do {
  105.         *destString++ = *srcString++;
  106.     } while ( --index >= 0 );
  107. }
  108.